<template>
	<div>
		<el-dialog :title="title" :width="dialogWidth" :close-on-click-modal="false" :close-on-press-escape="false"
		 :visible.sync="visible" :before-close="BeforeClose" top="1vh">
			<el-form v-if="visible" :model="inputForm" ref="inputForm" :rules="rules" v-loading="loading" :class="method==='view'?'readonly':''"
			 :disabled="method==='view'">
				<el-row :gutter="15">
					<div>
						<el-collapse v-model="activeName" @change="haChange">
							<el-collapse-item title="基本信息" name="1" disabled>
								<el-col :span="12">
									<el-form-item label="合同分类:" prop="contractTypeId" label-width="120px">
										<el-select style="width: 100%;" @change="contractTypechange" v-model="inputForm.contractTypeId" :disabled="method=='continue'"
										 placeholder="请选择" clearable>
											<el-option v-for="item in contractTypeList" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId!=2">
									<el-form-item label="房产类型:" prop="buildingType" label-width="120px">
										<el-select style="width: 100%;" :disabled="method=='continue' || this.inputForm.contractTypeId == 4"
										 v-model="inputForm.buildingType" placeholder="请选择" @change="getselectType(0)">
											<el-option v-for="item in proCompanyList" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId!=2">
									<el-form-item label="关联房产编号:" prop="ctContractProjectList" label-width="120px">
										<!--<el-input v-model="inputForm.companyId" placeholder="请输入"></el-input>-->
										<el-select filterable multiple style="width: 100%;" :disabled="method=='continue'" v-model="inputForm.ctContractProjectList"
										 placeholder="请选择" @change="ctContractProjectListchange">
											<el-option v-for="item in rmprojectList" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId!= 4">
									<el-form-item label="公司名称:" prop="companyId" label-width="120px">
										<el-select filterable style="width: 100%;" :disabled="method=='continue'" v-model="inputForm.companyId"
										 placeholder="请选择" @change="getsyscompanyId">
											<el-option v-for="item in companyNameList" :key="item.value" :label="item.label" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId!= 4">
									<el-form-item label="产权人:" label-width="120px">
										<el-input v-model="inputForm.belonger" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId!= 4">
									<el-form-item label="联系人:" prop="contactUserName" label-width="120px">
										<el-input disabled v-model="inputForm.contactUserName" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId!= 4">

									<el-form-item label-width="120px" label="联系方式:" prop="contactUserPhone">
										<el-input disabled v-model="inputForm.contactUserPhone" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId!= 4">
									<!-- <el-form-item
                    label="纳税人标识号:"
                    prop="taxpayerNumber"
                  > -->
									<el-form-item label="纳税人识别号:" label-width="120px">
										<el-input disabled v-model="inputForm.taxpayerNumber" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==0 || inputForm.contractTypeId==2">
									<el-form-item label="租赁起止日期:" label-width="120px" prop="dateall">
										<el-date-picker v-if="method!='continue'" @change="doCheckMonthStatus" v-model="inputForm.dateall" style="width:100%;"
										 type="daterange" value-format="yyyy-MM-dd" start-placeholder="租赁开始时间" end-placeholder="租赁结束日期">
										</el-date-picker>
										<el-date-picker v-if="method=='continue'" @change="doCheckMonthStatus" v-model="dateall" type="daterange"
										 value-format="yyyy-MM-dd" start-placeholder="租赁开始时间" end-placeholder="租赁结束日期">
										</el-date-picker>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==0 && inputForm.contractTypeId!=2">
									<el-form-item label="优惠时间(月):" label-width="120px">
										<el-input-number @change="discountTimechange" style="width:100%" v-model="inputForm.discountTime"
										 controls-position="right" :min="0" :max="MaxMonth"></el-input-number>
									</el-form-item>
								</el-col>

								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="房屋楼号/区域:" prop="projectTypeId" label-width="120px">
										<el-input disabled v-model="inputForm.projectTypeId" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="面积(㎡):" prop="rentArea" label-width="120px">
										<el-input disabled v-model="inputForm.rentArea" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
							</el-collapse-item>
							<el-collapse-item disabled title="购房人信息" name="2" v-if="inputForm.contractTypeId==4">
								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="名称:" prop="companyId" label-width="120px">
										<el-input disabled v-model="inputForm.companyName" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="地址:" prop="companyName" label-width="120px">
										<el-input disabled v-model="inputForm.companyName" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="联系人:" prop="contactUserName" label-width="120px">
										<el-input disabled v-model="inputForm.contactUserName" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="联系方式:" prop="contactUserPhone" label-width="120px">
										<el-input disabled v-model="inputForm.contactUserPhone" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
							</el-collapse-item>
							<el-collapse-item disabled title="市场管理服务费信息" name="2" v-if="inputForm.contractTypeId!=2">
								<el-col :span="12" v-if="inputForm.contractStatus==1">
									<el-form-item label="服务开始日期:" prop="serviceStartTime" label-width="120px">
										<el-date-picker @change="changeTime" style="width: 100%;" v-model="inputForm.serviceStartTime" type="date"
										 value-format="yyyy-MM-dd" placeholder="选择日期时间">
										</el-date-picker>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="服务月份:" prop="serviceMonth" label-width="120px">
										<el-select style="width: 100%;" @change="changeTime" v-model="inputForm.serviceMonth" placeholder="请选择"
										 clearable>
											<el-option v-for="item in serviceMonthList" :key="item.value" :label="item.description" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="服务起止日期:" prop="serviceTime" label-width="120px">
										<el-input disabled v-model="inputForm.serviceTime" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12" v-if="inputForm.contractTypeId==4">
									<el-form-item label="计费起止日期:" prop="serviceTime" label-width="120px">
										<el-input disabled v-model="inputForm.serviceCostTime" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="市场管理服务费单价(元/㎡/月):" required label-width="220px">
										<el-select @change="scglchange" v-model="scgl.unitPriceId" placeholder="请选择" clearable style="width:100%;">
											<el-option v-for="item in scglunitPriceIdList" :key="item.value" :label="item.label+'元/㎡'" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="市场管理服务费税率:" required label-width="220px">
										<el-select @change="scglchange" v-model="scgl.taxRateId" placeholder="请选择" clearable style="width:100%;">
											<el-option v-for="item in scgltaxRateIdList" :key="item.value" :label="item.label+'%'" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="市场管理服务费(含税元/年):" label-width="220px">
										<el-input disabled v-model="scgl.incTaxTotalAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>

								<el-col :span="12">
									<el-form-item label="市场管理服务费(无税元/年):" label-width="220px">
										<el-input disabled v-model="scgl.noTaxTotalAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="市场管理服务费税金:" label-width="220px">
										<el-input disabled v-model="scgl.taxAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="市场管理服务费合同总金额:" label-width="220px">
										<el-input disabled v-model="scgl.totalAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
							</el-collapse-item>
							<el-collapse-item disabled v-if="inputForm.contractTypeId==0 && inputForm.contractTypeId!=2" title="租金信息" name="3">
								<el-col :span="12">
									<el-form-item label="租金单价(元/㎡/月):" required label-width="180px">
										<el-select @change="zjxxchange" v-model="zjxx.unitPriceId" placeholder="请选择" clearable style='width:100%;'>
											<el-option v-for="item in zjxxunitPriceIdList" :key="item.value" :label="item.label+'元/㎡'" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="税率分类:" required label-width="180px">
										<el-select @change="zjxxchange" v-model="zjxx.taxRateId" placeholder="请选择" clearable style="width:100%;">
											<el-option v-for="item in zjxxtaxRateIdList" :key="item.value" :label="item.label+'%'" :value="item.value">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="税金:" label-width="180px">
										<el-input disabled v-model="zjxx.taxAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="含税合同金额(元/年):" label-width="180px">
										<el-input disabled v-model="zjxx.incTaxTotalAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="无税合同金额(元/年):" label-width="180px">
										<el-input disabled v-model="zjxx.noTaxTotalAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="租赁保证金(元):" label-width="180px">
										<el-input @blur="guaranteeAmountchange" v-model="zjxx.guaranteeAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="12">
									<el-form-item label="合同总金额:" label-width="180px">
										<el-input disabled v-model="zjxx.totalAmount" placeholder="请输入"></el-input>
									</el-form-item>
								</el-col>
								<el-table v-if="method==='view'" :data="tableFileData" border :cell-style="rowClass" :header-cell-style="headClass"
								 style="width: 100%">
									<el-table-column prop="fileName" label="附件名称">
									</el-table-column>
									<el-table-column prop="createBy" label="上传人" width="150">
									</el-table-column>
									<el-table-column prop="createDate" width="120" label="上传时间">
									</el-table-column>
									<el-table-column header-align="center" align="center" fixed="right" width="180" label="操作">
										<template slot-scope="scope">
											<el-button type="text" size="small" @click="downloadFile(scope.row.id)">下载</el-button>
											<el-button type="text" size="small" @click="del(scope.row.id)">删除</el-button>
										</template>
									</el-table-column>
								</el-table>
							</el-collapse-item>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="位置:" prop="advertisingLocation" label-width="180px">
									<el-input v-model="inputForm.advertisingLocation" placeholder="请输入位置"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="数量:" prop="advertisingCount" label-width="180px">
									<el-input @change="getAllTotoalMoney" @input.native="inputForm.advertisingCount = tests(inputForm.advertisingCount)"
									 @keyup.native="inputForm.advertisingCount = tests(inputForm.advertisingCount)" v-model="inputForm.advertisingCount"
									 @blur="getAllTotoalMoney" placeholder="请输入数量"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="长:" prop="advertisingLength" label-width="180px">
									<el-input @blur="getAllTotoalMoney" @change="getAllTotoalMoney" v-model="inputForm.advertisingLength"
									 @keyup.native="inputForm.advertisingLength = test(inputForm.advertisingLength,getAllTotoalMoney)"
									 @input.native='inputForm.advertisingLength = test(inputForm.advertisingLength,getAllTotoalMoney)' placeholder="请输入长"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="宽:" prop="advertisingWidth" label-width="180px">
									<el-input @blur="getAllTotoalMoney" @change="getAllTotoalMoney" @input.native='inputForm.advertisingWidth = test(inputForm.advertisingWidth,getAllTotoalMoney)'
									 @keyup.native="inputForm.advertisingWidth = test(inputForm.advertisingWidth,getAllTotoalMoney)" v-model="inputForm.advertisingWidth"
									 placeholder="请输入宽"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="类型:" prop="advertisingType" label-width="180px">
									<el-select style="width:100%" v-model="inputForm.advertisingType" placeholder="请选择类型">
										<el-option v-for="(item,index) in advertisingTypeOption" :key="index" :label="item.label" :value="item.value"></el-option>
									</el-select>
									<!-- <el-input
                    @change="getAllTotoalMoney"
                    v-model="inputForm.advertisingType"
                    placeholder="请输入面积"
                  ></el-input> -->
								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="面积(㎡):" prop="advertisingArea" label-width="180px">
									<el-input @blur="getAllTotoalMoney" @change="getAllTotoalMoney" v-model="inputForm.advertisingArea"
									 @input.native='inputForm.advertisingArea = test(inputForm.advertisingArea)' @keyup.native="inputForm.advertisingArea = test(inputForm.advertisingArea)"
									 placeholder="请输入面积"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="租金单价(元/㎡/月):" prop="advertisingUnitPrice" label-width="180px">
									<el-input @blur="getAllTotoalMoney" @change="getAllTotoalMoney" @input.native='inputForm.advertisingUnitPrice = test(inputForm.advertisingUnitPrice)'
									 @keyup.native="inputForm.advertisingUnitPrice = test(inputForm.advertisingUnitPrice)" v-model="inputForm.advertisingUnitPrice"
									 placeholder="输入租金单价(元/㎡/月):" label-width="180px"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="租金总额(元):" prop="contractTotalAmount" label-width="180px">
									<el-input v-model="contractTotalAmount" disabled placeholder="输入租金总额(元)" style="width:100%"></el-input>

								</el-form-item>
							</el-col>
							<el-col :span="12" v-if="inputForm.contractTypeId==2">
								<el-form-item label="优惠价格(元):" label-width="180px">
									<!-- <el-input
                    v-model="inputForm.advertisingPreferentialPrice"
                    @input.native='inputForm.advertisingPreferentialPrice = test(inputForm.advertisingPreferentialPrice)'
                    @keyup.native="inputForm.advertisingPreferentialPrice = test(inputForm.advertisingPreferentialPrice)"
                    placeholder="输入 优惠价格(元)"
                  ></el-input> -->
									<el-input v-model="inputForm.advertisingPreferentialPrice" placeholder="输入 优惠价格(元)"></el-input>
								</el-form-item>
							</el-col>
<!--							<el-col :span="12">-->
<!--								<el-form-item label="合同状态:" prop="contractStatus" label-width="180px">-->
<!--									<el-radio-group :disabled="method=='continue'" v-model="inputForm.contractStatus" style="width:80%;" @change="contractStatusChange">-->
<!--										<el-radio :label=1>已签</el-radio>-->
<!--										<el-radio :label=0>未签</el-radio>-->
<!--									</el-radio-group>-->
<!--								</el-form-item>-->
<!--							</el-col>-->
							<el-col :span="12" v-if="inputForm.contractStatus==1">
								<el-form-item label="签订日期:" prop="signDate" label-width="180px">
									<el-date-picker @change="signDateChange" style="width: 100%;" v-model="inputForm.signDate" type="date"
									 value-format="yyyy-MM-dd" placeholder="选择日期时间">
									</el-date-picker>
								</el-form-item>
							</el-col>
						</el-collapse>
					</div>
				</el-row>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="BeforeClose" icon="el-icon-circle-close">取 消</el-button>
				<el-button type="primary" icon="el-icon-circle-check" v-if="method != 'view'" @click="doSubmit()">提 交</el-button>
			</span>
		</el-dialog>

		<!--租赁房产-->
		<el-dialog title="租赁房产" :visible.sync="showProjectForm" :close-on-click-modal="false" :close-on-press-escape="false">
			<el-form ref="ruleFormProjectTable" :rules="rulesProject" :model="proProData">
				<el-form-item label="房产类型:" prop="buildingTypes">
					<el-select v-model="proProData.buildingType" placeholder="请选择" style="width:80%;">
						<el-option v-for="item in proBuildTypeList" :key="item.buildingType" :label="item.typeName" :value="item.buildingType">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="关联房间号:" prop="projectIds">
					<el-select v-model="proProData.projectId" placeholder="请选择" style="width:80%;">
						<el-option v-for="item in proProjectList" :key="item.id" :label="item.projectName" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button v-on:click="do_cancel_project()" icon="el-icon-circle-close">取 消</el-button>
				<el-button icon="el-icon-circle-check" type="primary" v-on:click="do_save_project()">确 定</el-button>
			</div>
		</el-dialog>
		<!--市场管理服务费，租金信息-->
		<el-dialog :title="tabletitle" :visible.sync="showForm" :close-on-click-modal="false" :close-on-press-escape="false">
			<el-form ref="ruleFormTable" :model="tableForm">
				<el-form-item label="关联房产编号" prop="projectId">
					<el-select filterable @change="onChangeProjectData" v-model="tableForm.projectId" placeholder="请选择" style="width:80%;">
						<el-option v-for="item in proProjectData" :key="item.projectId" :label="item.projectName" :value="item.projectId">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item :label="tableMethod=='1'?'市场管理费单价(元/㎡.月)':'租金单价(元/㎡.月)'" prop="unitPriceId">
					<el-select @change="onChangeUnitPrice" v-model="tableForm.unitPriceId" placeholder="请选择" style="width:80%;">
						<el-option v-for="item in proUnitpPriceList" :key="item.id" :label="item.unitPrice" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="税率" prop="taxRateId">
					<el-select @change="onChangeTaxRate" v-model="tableForm.taxRateId" placeholder="请选择" style="width:80%;">
						<el-option v-for="item in proTaxRateList" :key="item.id" :label="item.taxRate" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button v-on:click="do_cancel_charge()" icon="el-icon-circle-close">取 消</el-button>
				<el-button type="primary" icon="el-icon-circle-check" v-on:click="do_save_charge()">确 定</el-button>
			</div>
		</el-dialog>

	</div>
</template>
<script>
	import {
		tableMarketOption
	} from '@/const/crud/market/contract/person'
	import {
		getObj,
		addObj,
		putObj,
		getContractTaxRateList,
		getContractType,
		getChargeUnitpPriceList,
		getProjectList,
		getCompanyList,
		uploadFile,
		getCompanyByPhone,
		syscompanyid,
		selectType,
		calculation,
		relet,
		getRentNumber,
		findReProjectByNum,
		findCtContractByContractNumber
	} from '@/api/market/contract/person'
	import {
		contractServiceCharge,
		contractServiceTaxRate,
		contractRentCharge,
		contractRentTaxRate
	} from "@/api/dicdata"
	import {
		getDicType
	} from '@/api/common'
	import {
		getProjectType,
		getProjectStatus,
		getProjectpProperty
	} from '@/api/market/estate/rmproject'
	import {
		mapGetters
	} from 'vuex'
	import store from "@/store"
	import {
		getStore
	} from '@/util/store'
	//import { getStore } from '../util/store'

	export default {
		data() {
			var validatePass = (rule, value, callback) => {
				if (!value.length) {
					callback(new Error('不能为空'));
				} else {
					callback();
				}
			}
			return {
				state1: '',
				totalMonthNumber: 0, //租赁总月份
				title: '',
				tabletitle: '',
				dialogWidth: '50%',
				page: {
					//current: 1, // 当前页数
					size: -1 // 每页显示多少条
				},
				method: '',
				headers: {
					Authorization: 'Bearer ' + store.getters.access_token,
					tenantId: 0
				},
				filedata: {
					remarks: '',
					uploadPath: 'user/path'
				},
				dateall: [],
				file: null,
				tableIndex: 0,
				tableRowId: '',
				dialogStatus: "add",
				showForm: false,
				showProjectForm: false,
				visible: false,
				loading: false,
				tableCount: 0,
				tableMethod: '',
				moenyCount: 3,
				companyNmae: '',
				guaranteeAmount: '',
				contractMonth: 0, //合同计算是月份差
				projectArea: 0, //面积
				unitPrice: 0, //单价
				taxRate: 0, //税率
				ctContractFileLists: [],
				companyNameList: [], //公司名称列表
				rulesProject: {
					buildingTypes: [{
						required: true,
						message: "房产类型不能为空",
						trigger: "blur"
					}],
					projectIds: [{
						required: true,
						message: "关联房间号不能为空",
						trigger: "blur"
					}]
				},
				tableFormIndex: 0,
				//服务费
				tableForm: {
					id: '',
					rowIndex: 0,
					projectId: '', //关联房产ID
					projectName: '', //关联房产名称
					projectBuildingId: '', //房产类型Id
					projectBuildName: '', //房产类型
					projectArea: '', //房产面积
					chargeType: 0, //1.市场管理费 2.租金 3.租赁保证金
					unitPriceId: '', //单价 id
					unitPrice: '', //单价
					taxRateId: '', //税率
					taxRate: '', //税率id
					incTaxTotalAmount: 0, //含税金额
					noTaxTotalAmount: 0, //不含税金额
					taxAmount: 0, //税金
					totalAmount: 0, //总金额
					guaranteeAmount: 0, //租赁保证金 chargeType为3
				},
				//合同账单
				tableBillForm: {
					projectBuildingId: '',
					projectName: '',
					projectArea: 0,
					chargeType: 0, //1.市场管理服务费 2.租金 3.合同保证金
					unitPrice: '',
					billStartTime: '',
					billEndTime: '',
					billCost: 0, //应收金额
				},
				proProjectData: [], //租赁房产table列表
				tableMarketData: [], //市场服务费table列表
				tableRentData: [], //租金服务费table列表
				tableBillData: [], //合同账单table列表
				tableFileData: [],
				proBuildTypeList: [],
				rmprojectList: [], //房产编号
				scglunitPriceIdList: [], //市场管理服务费
				scgltaxRateIdList: [],
				zjxxunitPriceIdList: [],
				zjxxtaxRateIdList: [],
				proProData: {
					buildingType: '',
					projectId: '', //关联房产ID
					projectName: '',
					projectArea: '',
					buildingTypeName: ''
				},
				proCompanyList: [], //获取公司数据
				proProjectList: [], //获取房产数据
				proTaxRateList: [], //税率
				proUnitpPriceList: [], //单价
				fileList: [],
				fileLists: [],
				activeName: ['1', '2', '3'],
				contractTypeList: [{
				  value:'1',
          label:'房产租赁'
        },{
          value:'2',
          label:'仓储租赁'
        },{
          value:'3',
          label:'会议室租赁'
        }],
				serviceMonthList: [],
				inputForm: {
					id: '',
					contractTypeId: '', //合同分类
					buildingType: '', //房产类型
					companyId: '', //公司id
					companyName: '', //公司名称
					contractNumber: '', //合同编号
					belonger: '', //产权人
					taxpayerNumber: '', //纳税人识别号
					discountTime: '', //优惠月数
					contactUserName: '', //联系人、联系方式
					contactUserPhone: '',
					rentEndTime: '',
					rentStartTime: '', //租赁开始日期
					discountEndTime: '',
					discountStartTime: '',
					contractTotalAmount: 0, //合同总金额
					// contractStatus: 1,
					signDate: '', //签订日期
					ctContractChargeSummary: [], //各种费用  //费用类型(1.市场管理费 2.租金 3.租赁保证金)
					// blChargeBillList: [], //合同账单
					// ctContractFileList: [], //上传文件
					ctContractProjectList: [], //房产id集合
					// ctContractProjectList: '', //房产id集合(不能多选)
					dateall: [],
					advertisingLocation: '',
					advertisingCount: '',
					advertisingLength: '',
					advertisingWidth: '',
					advertisingArea: '',
					advertisingType: '',
					advertisingUnitPrice: '',


					projectTypeId: '',
					rentArea: 0,
					serviceStartTime: '',
					serviceMonth: "12",
					serviceTime: '',
					serviceCostTime: ''
				},
				scgl: {
					chargeType: 1,
					unitPriceId: '',
					taxRateId: '',
					incTaxTotalAmount: 0,
					noTaxTotalAmount: 0,
					taxAmount: 0,
					totalAmount: 0,
				},
				contractTotalAmount: '',
				zjxx: {
					chargeType: 2,
					unitPriceId: '',
					taxRateId: '',
					incTaxTotalAmount: 0,
					noTaxTotalAmount: 0,
					taxAmount: 0,
					totalAmount: 0,
					guaranteeAmount: 0,
					remarks: ''
				},
				MaxMonth: 0, //最大月份
				// 续租时间是否改变过，
				isChangeDate: false,
				// 表单校验
				rules: {
					advertisingLocation: [{
						required: true,
						message: "位置不能为空",
						trigger: "blur"
					}],
					advertisingCount: [{
						required: true,
						message: "位置不能为空",
						trigger: "blur"
					}],
					advertisingLength: [{
						required: true,
						message: "长度不能为空",
						trigger: "blur"
					}],
					advertisingWidth: [{
						required: true,
						message: "宽度不能为空",
						trigger: "blur"
					}],
					advertisingArea: [{
						required: true,
						message: "面积不能为空",
						trigger: "blur"
					}],
					advertisingType: [{
						required: true,
						message: "请选择类型",
						trigger: "blur"
					}],
					advertisingUnitPrice: [{
						required: true,
						message: "单价不能为空",
						trigger: "blur"
					}],
					buildingType: [{
						required: true,
						message: "房产类型不能为空",
						trigger: "change"
					}],
					dateall: [{
						required: true,
						message: "合同开始日期不能为空",
						trigger: "change"
					}],
					rentEndTime: [{
						required: true,
						message: "合同结束日期不能为空",
						trigger: "blur"
					}],
					signDate: [{
						required: true,
						message: "合同签订日期不能为空",
						trigger: "blur"
					}],
					contractNumber: [{
						required: true,
						message: "合同编号不能为空",
						trigger: "blur"
					}],
					contractTypeId: [{
						required: true,
						message: "合同类型不能为空",
						trigger: "blur"
					}],
					taxpayerNumber: [{
						required: true,
						message: "纳税人识别号不能为空",
						trigger: "blur"
					}],
					contactUserName: [{
						required: true,
						message: "联系人不能为空",
						trigger: "blur"
					}],
					contactUserPhone: [{
						required: true,
						message: "联系方式不能为空",
						trigger: "blur"
					}],
					companyId: [{
						required: true,
						message: "公司名称不能为空",
						trigger: "blur"
					}, {
						required: true,
						message: "公司名称不能为空",
						trigger: "change"
					}],
					ctContractProjectList: [{
						required: true,
						message: "关联房产编号不能为空",
						trigger: "blur"
					}, {
						required: true,
						message: "关联房产编号不能为空",
						trigger: "change"
					}],
				},
				scglcalculationList: [],
				zjxxcalculationList: [],
				allcalculationList: [],
				advertisingTypeOption: [],
				newList: []
			}
		},
		created() {
			this.headers.tenantId = getStore({
				name: 'tenantId'
			})
		},
		methods: {
			BeforeClose() {
				this.visible = false
				if (this.$refs.inputForm) {
					this.$refs.inputForm.resetFields()
					this.$refs.inputForm.clearValidate()
				}
			},
			test(value, callback) {
				if (value) {
					value = value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$',
						'.').replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')
				}
				if (callback) {
					callback()
				}
				return value
			},
			tests(value) {
				if (value) {
					value = value.replace(/[^\d]/g, '')
				}
				return value
			},
			getAllTotoalMoney() {
				if (this.inputForm.advertisingLength > 0 && this.inputForm.advertisingWidth > 0) {
					this.inputForm.advertisingArea = this.inputForm.advertisingLength * this.inputForm.advertisingWidth
				}
				if (this.inputForm.contractTypeId != 2 || !this.inputForm.advertisingType || !this.inputForm.advertisingArea || !
					this.inputForm.advertisingCount || this.inputForm.dateall.length != 2 || !this.inputForm.advertisingUnitPrice) {
					return
				}
				calculation({
					contractTypeId: this.inputForm.contractTypeId,
					advertisingArea: this.inputForm.advertisingArea,
					advertisingType: this.inputForm.advertisingType,
					advertisingCount: this.inputForm.advertisingCount,
					advertisingUnitPrice: this.inputForm.advertisingUnitPrice,
					rentEndTime: this.inputForm.contractTypeId != 1 ? this.inputForm.dateall[1].substr(0, 10) : null,
					rentStartTime: this.inputForm.contractTypeId != 1 ? this.inputForm.dateall[0].substr(0, 10) : null,
				}).then((data) => {
					this.inputForm.contractTotalAmount = JSON.stringify(data.data.data[0].totalAmount)
					this.contractTotalAmount = this.inputForm.contractTotalAmount
					this.newList = data.data.data
				})
			},
			contractStatusChange() {
				this.inputForm.signDate = ''
				if (this.inputForm.contractTypeId == 0) {
					this.zjxxchange()
				}
			},
			contractTypechange() {
				console.log(this.inputForm.contractTypeId)
				if (this.$refs.inputForm) {
					this.$refs.inputForm.clearValidate();
				}
				if (this.inputForm.contractTypeId != 0) {
					this.zjxx = this.$options.data().zjxx
					if (this.inputForm.contractTypeId == 4) {
						this.ctContractProjectList = []
						this.getRentNumber()
						this.scglchange()
					} else {
						this.getAllTotoalMoney()
					}
				} else {
					this.scglchange()
					this.zjxxchange()
				}
			},
			guaranteeAmountchange() {
				if (this.zjxx.guaranteeAmount != '') {
					if (this.inputForm.contractTypeId == 0) {
						this.zjxxchange()
					}
				}
			},
			discountTimechange() {
				this.scglchange()
				if (this.inputForm.contractTypeId == 0) {
					this.zjxxchange()
				}
			},
			//
			findReProjectByNum(projectNumber) {
				findReProjectByNum({
					"projectNumber": projectNumber
				}).then((data) => {
					let res = {
						"id": 2679,
						"projectStatus": 1,
						"projectArea": 140,
						"projectName": "A2-8",
						"projectFloorNumber": 0,
						"projectRegionId": "1",
						"projectRegionStage": "1",
						"buildingType": "exhibition",
						"projectUnitPrice": null,
						"serviceUnitPrice": null,
						"projectDirection": null,
						"rentTaxRate": null,
						"serviceTaxRate": null,
						"projectProperty": 1,
						"projectNumber": "A2-8",
						"projectImage": null,
						"createBy": null,
						"createDate": "2020-10-13 15:37:57",
						"updateBy": 1,
						"updateDate": "2020-10-13 15:37:57",
						"remarks": null,
						"delFlag": "0",
						"tenantId": 1,
						"contractNumber": null,
						"rentType": 2,
						"ctContract": null,
						"ctContractProjectList": null,
						"sysProjectType": null
					}

					console.log(data)
					if (res) {
						this.inputForm.projectTypeId = res.projectRegionId
						this.inputForm.rentArea = res.projectArea
						this.inputForm.buildingType = res.buildingType
					}
				})
			},
			ctContractProjectListchange() {

				if (this.inputForm.ctContractProjectList.length > 0) {
					// if (this.inputForm.ctContractProjectList) {
					for (let i = 0; i < this.rmprojectList.length; i++) {
						if (this.rmprojectList[i]['label'] == this.inputForm.ctContractProjectList[0]) {
							this.findReProjectByNum(this.rmprojectList[i]['label'])
							break;
						}
					}

					this.scglchange()

					if (this.inputForm.contractTypeId == 0) {
						this.zjxxchange()
					}
				}
			},
			findCtContractByContractNumber(contractNumbe) {
				findCtContractByContractNumber({
					'contractNumbe': contractNumbe
				}).then((data) => {
					if (data.data.data) {
						let contract = data.data.data
						console.log(contract)
            this.inputForm.companyId = contract.companyId
						this.inputForm.companyName = contract.companyName
						this.inputForm.contactUserName = contract.contactUserName
						this.inputForm.contactUserPhone = contract.contactUserPhone
					}
				})
			},
			scglchange() {
				// if ((this.inputForm.dateall.length != 2 || this.inputForm.ctContractProjectList.length == 0) && !this.inputForm.signDate) {
				if ((this.inputForm.dateall.length != 2 || this.inputForm.ctContractProjectList.length == 0) && this.inputForm.contractTypeId !=
					1) {
					// if ((this.inputForm.dateall.length != 2 || !this.inputForm.ctContractProjectList) && this.inputForm.contractTypeId != 1) {
					return
				}
				if (!(this.inputForm.contractTypeId == 1 || this.inputForm.contractTypeId == 0)) {
					return
				}
				if (this.inputForm.ctContractProjectList.length == 0) {
					// if (!this.inputForm.ctContractProjectList) {
					return
				}
				if (this.scgl.unitPriceId && this.scgl.taxRateId) {
					calculation({
						ids: this.inputForm.ctContractProjectList,
						// ids: [this.inputForm.ctContractProjectList],
						type: 0,
						unitPriceId: this.scgl.unitPriceId.replace('元/㎡.月', ''),
						taxRateId: this.scgl.taxRateId.replace('%', ''),
						discountTime: this.inputForm.discountTime,
						contractTypeId: this.inputForm.contractTypeId,
						// signDate: this.inputForm.signDate,
						rentEndTime: this.inputForm.contractTypeId != 1 ? this.inputForm.dateall[1].substr(0, 10) : null,
						rentStartTime: this.inputForm.contractTypeId != 1 ? this.inputForm.dateall[0].substr(0, 10) : null
					}).then((data) => {
						let id = null
						if (this.scglcalculationList.length > 0) {
							id = this.scglcalculationList[0].id
						}
						this.scglcalculationList = data.data.data
						if (this.scglcalculationList.length > 0) {
							this.scglcalculationList[0].id = id
						}
						this.scgl.incTaxTotalAmount = 0
						this.scgl.noTaxTotalAmount = 0
						this.scgl.taxAmount = 0
						this.scgl.totalAmount = 0
						for (var i = 0; i < data.data.data.length; i++) {
							this.scgl.incTaxTotalAmount = (this.scgl.incTaxTotalAmount + data.data.data[i].incTaxTotalAmount).toFixed(2)
							this.scgl.noTaxTotalAmount = (this.scgl.noTaxTotalAmount + data.data.data[i].noTaxTotalAmount).toFixed(2)
							this.scgl.taxAmount = (this.scgl.taxAmount + data.data.data[i].taxAmount).toFixed(2)
							this.scgl.totalAmount = (this.scgl.totalAmount + data.data.data[i].totalAmount).toFixed(2)
						}
					})
				}
			},
			changeTime() {
				let that = this
				that.inputForm.dateall = []
				let mm = this.inputForm.serviceMonth
				const dt = new Date(that.inputForm.serviceStartTime)
				const y = dt.getFullYear()
				const m = (dt.getMonth() + 1 + '').padStart(2, '0')
				const d = (dt.getDate() + '').padStart(2, '0')
				var newM = parseInt(m) + parseInt(mm)

				// console.log(newM)
				if (newM > 12) {
					let remainder = Math.floor(newM / 12)
					var endY = y + remainder
					var endM = newM - 12 * remainder
					that.inputForm.serviceTime = `${y}-${m}-${d}~${endY}-${endM}-${d}`
					//that.rentEndTime = `${endY}-${endM}-${d}`
				}

				if (newM <= 12) {
					const LessThanY = y
					const LessThanM = newM
					that.inputForm.serviceTime = `${y}-${m}-${d}~${LessThanY}-${LessThanM}-${d}`
					//that.rentEndTime = `${endY}-${endM}-${d}`
				}
				//计费起始时间段
				if (mm > 12) {
					var newM = parseInt(m) + 12
				} else {
					var newM = parseInt(m) + parseInt(mm)
				}
				if (newM > 12) {
					let remainder = Math.floor(newM / 12)
					var endY = y + remainder
					var endM = newM - 12 * remainder
					that.inputForm.serviceCostTime = `${y}-${m}-${d}~${endY}-${endM}-${d}`
					//that.rentEndTime = `${endY}-${endM}-${d}`
					that.inputForm.dateall.push(`${y}-${m}-${d}`)
					that.inputForm.dateall.push(`${endY}-${endM}-${d}`)
				}

				if (newM <= 12) {
					const LessThanY = y
					const LessThanM = newM
					that.inputForm.serviceCostTime = `${y}-${m}-${d}~${LessThanY}-${LessThanM}-${d}`
					//that.rentEndTime = `${endY}-${endM}-${d}`
					that.inputForm.dateall.push(`${y}-${m}-${d}`)
					that.inputForm.dateall.push(`${LessThanY}-${LessThanM}-${d}`)
				}

			},
			signDateChange() {
				if (this.inputForm.contractStatus === 0) {
					this.zjxxchange()
				}
				if (this.inputForm.contractStatus === 1 || this.inputForm.contractStatus === 0) {
					this.scglchange()
				}
			},
			zjxxchange() {
				if (this.zjxx.unitPriceId && this.zjxx.taxRateId && this.zjxx.guaranteeAmount >= 0) {
					if (!(this.inputForm.contractTypeId == 0)) {
						return
					}
					if (!this.inputForm.dateall.length && this.inputForm.dateall.length < 2) {
						return
					}
					if (this.inputForm.ctContractProjectList.length == 0) {
						// if (!this.inputForm.ctContractProjectList) {
						return
					}
					calculation({
						ids: this.inputForm.ctContractProjectList,
						// ids: [this.inputForm.ctContractProjectList],
						type: 1,
						contractTypeId: this.inputForm.contractTypeId,
						unitPriceId: this.zjxx.unitPriceId.replace('元/㎡.月', ''),
						taxRateId: this.zjxx.taxRateId.replace('%', ''),
						discountTime: this.inputForm.discountTime,
						// signDate: this.inputForm.signDate,
						rentEndTime: this.inputForm.contractTypeId != 1 ? this.inputForm.dateall[1].substr(0, 10) : null,
						rentStartTime: this.inputForm.contractTypeId != 1 ? this.inputForm.dateall[0].substr(0, 10) : null,
						guaranteeAmount: this.zjxx.guaranteeAmount ? this.zjxx.guaranteeAmount : 0
					}).then((data) => {
						let id = null
						if (this.zjxxcalculationList.length > 0) {
							id = this.zjxxcalculationList[0].id
						}
						this.zjxxcalculationList = data.data.data
						if (this.zjxxcalculationList.length > 0) {
							this.zjxxcalculationList[0].id = id
						}
						this.zjxx.incTaxTotalAmount = 0
						this.zjxx.noTaxTotalAmount = 0
						this.zjxx.taxAmount = 0
						this.zjxx.totalAmount = 0
						for (var i = 0; i < data.data.data.length; i++) {
							this.zjxx.incTaxTotalAmount = (this.zjxx.incTaxTotalAmount + data.data.data[i].incTaxTotalAmount).toFixed(2)
							this.zjxx.noTaxTotalAmount = (this.zjxx.noTaxTotalAmount + data.data.data[i].noTaxTotalAmount).toFixed(2)
							this.zjxx.taxAmount = (this.zjxx.taxAmount + data.data.data[i].taxAmount).toFixed(2)
							this.zjxx.totalAmount = (this.zjxx.totalAmount + data.data.data[i].totalAmount).toFixed(2)
						}
					})
				}
			},
			// 多图片上传
			handleChanged(raw) {
				this.fileLists.push(raw.file);
				// this.fileList = raw
			},
			// 通过公司名称获取信息
			getsyscompanyId(val) {
				this.companyNameList.forEach(item => {
					if (this.inputForm.companyId == item.value) {
						this.inputForm.companyName = item.label
					}
				})
				syscompanyid({}, this.inputForm.companyId).then((data) => {
					this.inputForm.taxpayerNumber = data.data.data.taxRateNumber
					this.inputForm.contactUserPhone = data.data.data.contactPhone
					this.inputForm.contactUserName = data.data.data.contactName
				})
			},
			// 通过房产类型获取房产编号
			getselectType(type) {
				if (!type) {
					this.inputForm.ctContractProjectList = []
					// this.inputForm.ctContractProjectList = ''
				}
				let typeId = 0
				if (this.method === 'add') {
					typeId = 0
				} else {
					typeId = 1
				}
				selectType({}, this.inputForm.buildingType, typeId).then((data) => {
					this.rmprojectList = data.data.data
				})
			},
			//获取已销售合同的房产编号
			getRentNumber() {
				getRentNumber().then((data) => {
					let res = data.data.data
					this.rmprojectList = []
					res.forEach(item => {
						this.rmprojectList.push({
							'value': item['projectNumber'],
							'label': item['projectNumber']
						})
					})
				})
			},
			//获取附件数据
			getFile() {
				//获取文件方法
				getFileList().then(response => {
					if (response.data != null) {
						this.tableFileData = response.data.data.records;
					}
				});
			},
			onChangeProjectData: function() {
				var that = this;
				var objProject = that.proProjectList.find(function(item) {
					return item.projectId === that.tableForm.projectId
				})
				that.projectArea = objProject.projectArea;
			},
			onChangeUnitPrice: function() {
				var that = this;
				var objPrice = that.proUnitpPriceList.find(function(item) {
					return item.id === that.tableForm.unitPriceId
				})
				that.unitPrice = objPrice.unitPrice;
			},
			onChangeTaxRate: function() {
				var that = this;
				var objTaxRate = that.proTaxRateList.find(function(item) {
					return item.id === that.tableForm.taxRateId
				})
				that.taxRate = objTaxRate.taxRate;
			},
			// 表头样式设置
			headClass() {
				return 'text-align: center;background:#fafafa;'
			},
			// 表格样式设置
			rowClass() {
				return 'text-align: center;'
			},
			haChange(val) {
				// console.log(val);
			},
			//租赁房产
			//删除
			deleteProjectRow(index, rows) {
				rows.splice(index, 1);
			},
			editProjectRow: function(index, row) {
				var that = this;
				that.tableIndex = index,
					that.dialogStatus = 'edit',
					that.showProjectForm = true;
				that.proProData = Object.assign({}, row);
			},
			addProjrctForm: function() {
				var that = this;
				that.dialogStatus = 'add',
					that.showProjectForm = true;
				var listWorks = {
					buildingType: '',
					projectId: ''
				};
				this.$nextTick(function() {
					this.proProData = Object.assign({}, listWorks);
				})

			},
			do_cancel_project: function() {
				this.showProjectForm = false;
				this.$refs['ruleFormProjectTable'].resetFields();
			},
			do_save_project: function() {
				var that = this;

				var objProject = that.proProjectList.find(function(item) {
					return item.id === that.proProData.projectId
				})
				that.proProData.projectName = objProject.projectName;
				that.proProData.projectArea = objProject.projectArea;
				var objType = that.proBuildTypeList.find(function(item) {
					return item.buildingType === that.proProData.buildingType
				})
				that.proProData.buildingTypeName = objType.typeName;
				//新增赋值
				if (that.dialogStatus == "add") {
					that.proProjectData.push(that.proProData);
				}
				//修改赋值
				if (that.dialogStatus == "edit") {
					that.$set(that.proProjectData, that.tableIndex, that.proProData);
				}
				this.showProjectForm = false;
			},
			//市场管理服务费
			//删除
			deleteRow(index, rows) {
				rows.splice(index, 1);
			},
			//修改（市场管理服务费/租金）
			editRow: function(index, row) {
				var that = this;
				that.tableIndex = row.rowIndex;
				that.tableRowId = row.id;
				that.dialogStatus = 'edit';
				that.showForm = true;
				//获取单价getChargeUnitpPriceList chargeType 1.市场管理服务费 2.租金
				var query = {
					size: -1,
					chargeType: row.chargeType
				};
				getChargeUnitpPriceList(query).then(response => {
					if (response.data != null) {
						this.proUnitpPriceList = response.data.data.records;
					}
				})
				that.tableForm = Object.assign({}, row);
			},
			//新增（市场管理服务费/租金）
			addForm: function(method, id) {
				var that = this;
				if (that.proProjectData == [] || that.proProjectData.length <= 0) {
					this.$notify.success('请关联"租赁房产"后再操作！');
					return;
				}
				if (that.inputForm.rentStartTime == "") {
					this.$notify.success('请选择合同租赁开始时间！');
					return;
				}
				if (that.inputForm.rentEndTime == "") {
					this.$notify.success('请选择合同租赁结束时间！');
					return;
				}

				that.showForm = true;
				that.dialogStatus = 'add',
					that.tableMethod = method;
				if (method === '1') {
					this.tabletitle = `新增市场管理服务费`
				} else if (method === '2') {
					this.tabletitle = '新增租金'
				}
				//获取单价getChargeUnitpPriceList chargeType 1.市场管理服务费 2.租金
				var chargeType = method === '1' ? 1 : 2;
				var query = {
					size: -1,
					chargeType: chargeType
				};
				getChargeUnitpPriceList(query).then(response => {
					if (response.data != null) {
						this.proUnitpPriceList = response.data.data.records;
					}
				})

				//新增
				var listWork = {
					id: '',
					contractId: '',
					companyId: '',
					projectBuildingId: '',
					chargeType: 0,
					unitPriceId: '',
					taxRateId: '',
					incTaxTotalAmount: 0,
					noTaxTotalAmount: '',
					taxAmount: '',
					totalAmount: ''
				};
				this.$nextTick(function() {
					this.tableForm = Object.assign({}, listWork);
					if (method === '1') {
						this.tableForm.chargeType = 1;
					} else if (method === '2') {
						this.tableForm.chargeType = 2;
					}
				})
			},
			do_cancel_charge: function() {
				this.showForm = false;
				this.$refs['ruleFormTable'].resetFields();
			},
			//保存（市场管理服务费/租金）
			do_save_charge: function() {
				var that = this;
				var objProject = that.proProjectData.find(function(item) {
					return item.projectId === that.tableForm.projectId
				})
				that.tableForm.projectName = objProject.projectName;
				that.tableForm.buildingType = objProject.buildingType;
				that.tableForm.buildingTypeName = objProject.buildingTypeName;
				that.tableForm.projectArea = Number(objProject.projectArea || 0);

				var objUnitPrice = that.proUnitpPriceList.find(function(item) {
					return item.id === that.tableForm.unitPriceId
				})
				that.tableForm.unitPrice = Number(objUnitPrice.unitPrice || 0);

				var objTaxRate = that.proTaxRateList.find(function(item) {
					return item.id === that.tableForm.taxRateId
				})
				that.tableForm.taxRate = Number(objTaxRate.taxRate);
				//计算含税合同金额
				that.tableForm.incTaxTotalAmount = (that.tableForm.unitPrice * that.tableForm.projectArea * 12).toFixed(2);
				//计算无税合同金额
				that.tableForm.noTaxTotalAmount = (that.tableForm.incTaxTotalAmount / (1 + objTaxRate.taxRate * 0.01)).toFixed(
					2);
				//计算税率
				that.tableForm.taxAmount = (that.tableForm.noTaxTotalAmount * objTaxRate.taxRate * 0.01).toFixed(2);
				//计算总金额
				that.tableForm.totalAmount = (that.tableForm.incTaxTotalAmount * (that.totalMonthNumber / 12)).toFixed(2);

				that.tableForm.chargeType = that.tableMethod;

				var tableBillForm = {
					projectBuildingId: '',
					projectName: '',
					projectArea: 0,
					chargeType: 0,
					unitPrice: '',
					billStartTime: '',
					billEndTime: '',
					billCost: 0
				};
				tableBillForm.projectBuildingId = that.tableForm.projectBuildingId;
				tableBillForm.projectArea = that.projectArea;
				tableBillForm.chargeType = that.tableForm.chargeType;
				tableBillForm.unitPrice = that.unitPrice;
				tableBillForm.billCost = that.tableForm.totalAmount

				//新增赋值
				if (that.dialogStatus == "add") {
					that.tableFormIndex++;
					that.tableForm.rowIndex = that.tableFormIndex;
					that.inputForm.ctContractChargeSummary.push(that.tableForm);
					// that.inputForm.blChargeBillList.push(tableBillForm);
				}
				//修改赋值
				if (that.dialogStatus == "edit") {
					for (var i = 0; i < that.inputForm.ctContractChargeSummary.length; i++) {
						if (that.tableRowId == that.inputForm.ctContractChargeSummary[i].id && that.tableRowId) {
							that.tableIndex = i;
						} else if (that.tableIndex == that.inputForm.ctContractChargeSummary[i].rowIndex && that.inputForm.ctContractChargeSummary[
								i].rowIndex) {
							that.tableIndex = i;
						}
					}
					that.$set(that.inputForm.ctContractChargeSummary, that.tableIndex, that.tableForm);
					//that.$set(that.tableMarketData, that.tableIndex, that.tableForm);
				}
				//控制dialog显示/隐藏
				this.showForm = false;
			},
			//点击计算合同账单
			addBillForm: function() {
				var that = this;
				//that.inputForm.blChargeBillList=
			},
			handleRemove(file, fileList) {
				let removeIndex = -1
				this.fileLists.forEach((item, index) => {
					if (item.name == file.name) {
						removeIndex = index
					}
				})
				if (removeIndex >= 0) {
					this.fileLists.splice(removeIndex, 1)
				}
				console.log(this.fileLists)
			},
			//上传成功
			onFileSuccess(response, file, fileList) {
				var that = this;
				if (response.data != null) {
					var fileArry = {
						fileId: ''
					};
					response.data = (response.data || '') + '';
					fileArry.fileId = response.data;
					that.ctContractFileLists.push(fileArry);
				}
			},
			//上传文件
			handleChange(file, fileList) {
				this.fileList = fileList.slice(-3);
			},
			init(method, id) {
				this.visible = true
				const dt = new Date()
				const y = dt.getFullYear()
				const m = (dt.getMonth() + 1 + '').padStart(2, '0')
				const d = (dt.getDate() + '').padStart(2, '0')
				this.inputForm.serviceStartTime = `${y}-${m}-${d}`
				console.log(this.inputForm.serviceStartTime)
				// setTimeout(() => {
				this.inputForm.contractTypeId = ''
				this.fileList = []
				this.fileLists = []
				this.method = method
				this.inputForm.id = id
				if (method === 'add') {
					this.title = `新建合同`
				} else if (method === 'edit') {
					this.title = '修改合同'
				} else if (method === 'view') {
					this.title = '查看合同'
				} else if (method === 'continue') {
					this.title = '续租合同'
					this.isChangeDate = false
				}

				this.loading = false
				this.$nextTick(() => {
					// 获取公司名称
					getCompanyByPhone().then(response => {
						if (response.data != null) {
							this.companyNameList = response.data.data;
						}
					})
					getDicType('rm_project_buiding_type').then(res => {
						this.proCompanyList = res.data.data
					})
					// getDicType('contract_type').then(res => {
					//   console.log(res)
					// 	this.contractTypeList = res.data.data
					// })
					getDicType('month').then(res => {
						this.serviceMonthList = res.data.data
					})
					getDicType('advertising_type').then(res => {
						this.advertisingTypeOption = res.data.data
					})
					if (this.$refs.inputForm) {
						this.$refs.inputForm.clearValidate()
					}
					if (method === 'add' || method === 'edit' || method === 'continue') {
						this.inputForm = this.$options.data().inputForm
						this.inputForm.dateall = []
						// this.scgl = this.$options.data().scgl
						// this.zjxx = this.$options.data().zjxx
						this.scgl = {
							chargeType: 1,
							unitPriceId: '',
							taxRateId: '',
							incTaxTotalAmount: 0,
							noTaxTotalAmount: 0,
							taxAmount: 0,
							totalAmount: 0,
						}
						this.zjxx = {
							chargeType: 2,
							unitPriceId: '',
							taxRateId: '',
							incTaxTotalAmount: 0,
							noTaxTotalAmount: 0,
							taxAmount: 0,
							totalAmount: 0,
							guaranteeAmount: 0,
							remarks: ''
						}
						this.contractTotalAmount = ''
						this.inputForm.ctContractChargeSummary = [];
						// this.inputForm.blChargeBillList = [];
						this.inputForm.ctContractFileList = [];
						contractServiceCharge().then(res => {
							this.scglunitPriceIdList = res.data.data
						})
						contractServiceTaxRate().then(res => {
							this.scgltaxRateIdList = res.data.data
							this.zjxxtaxRateIdList = res.data.data
						})
						contractRentCharge().then(res => {
							this.zjxxunitPriceIdList = res.data.data
						})
						//新增时清空值
						//this.proProjectData=[];
						//this.tableMarketData=[];
						//this.tableRentData= [];
						//this.tableBillData=[];
					}
					if (method === 'edit' || method === 'view' || method === 'continue') { // 修改或者查看

						getObj(id).then(response => {
							this.inputForm = response.data.data;
							// 不多选的
							// this.inputForm.ctContractProjectList = this.inputForm.ctContractProjectList[0]
							if (this.inputForm.contractTypeId != 2) {
								this.getselectType(1);
							}
							var dateArr = []
							if (this.inputForm.rentStartTime && this.inputForm.rentEndTime) {
								dateArr[0] = this.inputForm.rentStartTime
								dateArr[1] = this.inputForm.rentEndTime
							}
							this.inputForm.dateall = dateArr
							this.dateall = dateArr
							// this.inputForm.dateall.push(this.inputForm.rentStartTime)
							// this.inputForm.dateall.push(this.inputForm.rentEndTime)
							this.inputForm.buildingType = this.inputForm.buildingType + ''
							this.inputForm.contractTypeId = this.inputForm.contractTypeId + ''
							this.scgl.incTaxTotalAmount = 0
							this.scgl.noTaxTotalAmount = 0
							this.scgl.taxAmount = 0
							this.scgl.totalAmount = 0
							this.zjxx.incTaxTotalAmount = 0
							this.zjxx.noTaxTotalAmount = 0
							this.zjxx.taxAmount = 0
							this.zjxx.totalAmount = 0
							this.zjxx.guaranteeAmount = 0
							this.scglcalculationList = []
							this.zjxxcalculationList = []
							if (response.data.data.contractTypeId == 2) {
								this.inputForm.contractTotalAmount = JSON.stringify(response.data.data.ctContractChargeSummaryList[0].totalAmount)
								this.contractTotalAmount = this.inputForm.contractTotalAmount
							}
							for (var i = 0; i < this.inputForm.ctContractChargeSummaryList.length; i++) {
								if (this.inputForm.ctContractChargeSummaryList[i].chargeType == 0) {
									this.scglcalculationList.push(this.inputForm.ctContractChargeSummaryList[i])
									this.scgl.unitPriceId = this.inputForm.ctContractChargeSummaryList[i].unitPriceId + '元/㎡.月'
									this.scgl.taxRateId = this.inputForm.ctContractChargeSummaryList[i].taxRateId + '%'
									this.scgl.incTaxTotalAmount = this.scgl.incTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].incTaxTotalAmount
									this.scgl.noTaxTotalAmount = this.scgl.noTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].noTaxTotalAmount
									this.scgl.taxAmount = this.scgl.taxAmount + this.inputForm.ctContractChargeSummaryList[i].taxAmount
									this.scgl.totalAmount = this.scgl.totalAmount + this.inputForm.ctContractChargeSummaryList[i].totalAmount
								}
								if (this.inputForm.ctContractChargeSummaryList[i].chargeType == 1) {
									this.zjxxcalculationList.push(this.inputForm.ctContractChargeSummaryList[i])
									this.zjxx.unitPriceId = this.inputForm.ctContractChargeSummaryList[i].unitPriceId + '元/㎡.月'
									this.zjxx.taxRateId = this.inputForm.ctContractChargeSummaryList[i].taxRateId + '%'
									this.zjxx.guaranteeAmount = this.inputForm.ctContractChargeSummaryList[i].guaranteeAmount
									this.zjxx.incTaxTotalAmount = this.zjxx.incTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].incTaxTotalAmount
									this.zjxx.noTaxTotalAmount = this.zjxx.noTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].noTaxTotalAmount
									this.zjxx.taxAmount = this.zjxx.taxAmount + this.inputForm.ctContractChargeSummaryList[i].taxAmount
									this.zjxx.totalAmount = this.zjxx.totalAmount + this.inputForm.ctContractChargeSummaryList[i].totalAmount
								}
							}
						})
					}
				})
				// }, 5)
			},
			// 手动校验
			ischceked(value) {
				if (value) {
					return false
				} else {
					return true
				}
			},
			// 表单提交
			doSubmit() {
				if (this.inputForm.contractTypeId == 1) {
					if (this.ischceked(this.scgl.unitPriceId)) {
						this.$message.warning('请选择市场管理服务费单价')
						return
					}
					if (this.ischceked(this.scgl.taxRateId)) {
						this.$message.warning('请选择市场管理服务费单价')
						return
					}
					// 产权人不是必填项
					// if (this.inputForm.contractTypeId == 1) {
					//   if (this.ischceked(this.inputForm.belonger)) {
					//     this.$message.warning('请填写产权人')
					//     return
					//   }
					// }
				}
				if (this.inputForm.contractTypeId == 0) {
					if (this.ischceked(this.zjxx.unitPriceId)) {
						this.$message.warning('请选择租金单价')
						return
					}
					if (this.ischceked(this.zjxx.taxRateId)) {
						this.$message.warning('请选择税率分类')
						return
					}
					// if (this.ischceked(this.zjxx.guaranteeAmount)) {
					//   this.$message.warning('请输入租赁保证金')
					//   return
					// }
				}
				if (this.method == "continue") {
					if (!this.isChangeDate) {
						this.$message.warning('请重新选择租赁的日期')
						return
					}
				}
				console.log(this.zjxx.guaranteeAmount)
				this.$refs['inputForm'].validate((valid) => {
					if (valid) {
						this.inputForm.contractTypeId = parseInt(this.inputForm.contractTypeId)
						let formdata = {}
						let array = []
						if (this.inputForm.contractTypeId == 1 || this.inputForm.contractTypeId == 0) {
							// this.inputForm.buildingType = parseInt(this.inputForm.buildingType)
							array.push(...this.scglcalculationList)
							if (this.inputForm.contractTypeId == 0) {
								array.push(...this.zjxxcalculationList)
							}
							formdata['ctContractChargeSummaryList'] = JSON.stringify(array)
						}
						if (this.inputForm.contractTypeId == 2) {
                formdata['ctContractChargeSummaryList'] = JSON.stringify(this.newList)
						}
						for (var key in this.inputForm) {
							if (typeof this.inputForm[key] == 'object') {
								if (this.inputForm[key] && key != 'ctContractChargeSummaryList') {
									// if (key == 'ctContractProjectList') {
									//   let arr = []
									//   arr.push(this.inputForm[key])
									//   formdata.append(key, JSON.stringify(arr))
									// } else {
									formdata[key] = JSON.stringify(this.inputForm[key])
									// }

								}
							} else {
								if (this.inputForm[key] || this.inputForm[key] == 0) {
									// if (key == 'ctContractProjectList') {
									//   let arr = []
									//   arr.push(this.inputForm[key])
									//   formdata.append(key, JSON.stringify(arr))
									// } else {
									formdata[key] = this.inputForm[key]
									// }
								}
							}
						}

						if (this.method == 'continue') {
							relet(formdata).then(response => {
								if (response.data.data) {
									this.BeforeClose()
									this.$emit('refreshDataList')
									this.$message.success('续租成功')
								} else {
									this.$notify.error('续租失败')
								}
							})
						} else {
							if (this.inputForm.id) {
								addObj(formdata).then(data => {
									this.$message.success('修改成功')
									this.$emit('refreshDataList')
									this.BeforeClose()
								});
							} else {
								console.log(formdata)
								addObj(formdata).then(data => {
								  this.$message.success('添加成功')
								  this.$emit('refreshDataList')
								  this.BeforeClose()
								})
							}
						}
					}
				})
			},
			createFilter(queryString, companyNameList) {
				return (companyNameList) => {
					// return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
					if (companyNameList && companyNameList.value) {
						return (companyNameList.value.indexOf(queryString) !== -1);
					} else {
						return companyNameList
					}
				};
			},
			querySearch(queryString, cb) {
				var restaurants = this.companyNameList;
				var results = queryString ? restaurants.filter(this.createFilter(queryString, this.companyNameList)) : restaurants;
				// 调用 callback 返回建议列表的数据
				cb(results);
			},
			handleSelect(item) {
				console.log(item);
			},
			//验证是否是整月
			doCheckMonthStatus() {
				var that = this;
				if (that.method == 'continue') {
					that.inputForm.dateall = JSON.parse(JSON.stringify(that.dateall))
				}
				if (!that.inputForm.dateall || that.inputForm.dateall.length == 0) {
					return;
				}
				let startd = ''
				let endd = ''
				// 下面6个参数用来获取当前月多少天的
				let starty = ''
				let startm = ''
				let startday = ''
				let endy = ''
				let endm = ''
				let endday = ''
				if (that.inputForm.dateall && that.inputForm.dateall.length > 0) {
					startd = that.inputForm.dateall[0].substr(8, 2)
					endd = that.inputForm.dateall[1].substr(8, 2)
					starty = that.inputForm.dateall[0].split('-')[0]
					startm = that.inputForm.dateall[0].split('-')[1]
					startday = that.inputForm.dateall[0].split('-')[2]

					endy = that.inputForm.dateall[1].split('-')[0]
					endm = that.inputForm.dateall[1].split('-')[1]
					endday = that.inputForm.dateall[1].split('-')[2]
				}
				// 判断是否是整月
				if (parseInt(startday) == 1) {
					if (new Date(endy, endm, 0).getDate() != parseInt(endday)) {
						this.$message.error('合同日期必须是整月');
						this.inputForm.dateall = []
						return;
					}
				} else if (parseInt(startday) > 1 && parseInt(startday) < new Date(starty, startm, 0).getDate()) {
					if (parseInt(endday) != (parseInt(startday) - 1)) {
						this.$message.error('合同日期必须是整月');
						this.inputForm.dateall = []
						return;
					}
				} else {
					if (parseInt(endday) != (new Date(endy, endm, 0).getDate() - 1)) {
						this.$message.error('合同日期必须是整月');
						this.inputForm.dateall = []
						return;
					}
				}
				if (this.method == "continue") {
					this.isChangeDate = true
				}
				this.inputForm.rentStartTime = this.inputForm.dateall[0]
				this.inputForm.rentEndTime = this.inputForm.dateall[1]
				if (that.inputForm.dateall && that.inputForm.dateall.length > 0) {
					let starty = parseInt(that.inputForm.dateall[0].substr(0, 4))
					let endy = parseInt(that.inputForm.dateall[1].substr(0, 4))
					let startm = parseInt(that.inputForm.dateall[0].substr(5, 2))
					let endm = parseInt(that.inputForm.dateall[1].substr(5, 2))
					this.MaxMonth = ((endy - starty) * 12) + (endm - startm)
					if (this.inputForm.contractTypeId == 0 || this.inputForm.contractTypeId == 1) {
						this.scglchange()
						if (this.inputForm.contractTypeId == 0) {
							this.zjxxchange()
						}
					} else {
						this.getAllTotoalMoney()
					}
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	/deep/.el-collapse-item__content {
		display: flex;
		flex-wrap: wrap;
	}
</style>
